﻿<%@ Page MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="DiliveryStrategyAdd.aspx.cs" Inherits="RabbitManage.UI.DiliveryStrategyAdd" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <form id="form1" action="../Action/DiliveryStrategyAdd.aspx" method="POST">
        
        <h3>邮费策略新增:</h3>

        <script type="text/javascript">

            form1.onsubmit = function (e) {
                e.preventDefault();

                var data = {};
                var provinceList = [];
                for (var i = 0, ii = form1.length; i < ii; ++i) {
                    var input = form1[i];
                    if (input.name) {
                        if (input.name == "selectedProvince") {
                            if (input.checked) {
                                provinceList.push(input.value);
                            }
                        }
                        else {
                            data[input.name] = input.value;
                        }
                    }
                }
                data["ProvinceList"] = provinceList;

                var xhr = new XMLHttpRequest();
                xhr.open(form1.method, form1.action, true);
                xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

                xhr.send(JSON.stringify(data));

                xhr.onloadend = function () {
                    // done
                    if (xhr.responseText == "true") {
                        window.location = "/UI/DiliveryStrategyList.aspx";
                    } else {
                        alert(xhr.responseText);
                    }
                };
            };
            
            function CheckAll() {
                var result = document.getElementById('selectAll').checked;
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].checked = result;
                }
            }

            function CheckReverse() {
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].checked = !inputs[i].checked;
                }
            }

            var afar = '<%=provinceAfar %>';
            function CheckNear() {
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[i];
                    if (afar.indexOf(input.value) == -1) {
                        input.checked = true;
                    } else {
                        input.checked = false;
                    }
                }
            }
        </script>
        <script type="text/javascript" src="/Share/js/city.js"></script>
        
        <table>
            <tr>
                <td>
                    规则名称：
                </td>
                <td>
                    <input type="text" id="inputStrategyName" name="StrategyName" style="width: 400px;" value="<%=stragegyName %>" />
                </td>
            </tr>
            <tr>
                <td>
                    运费：
                </td>
                <td>
                    <input type="text" id="inputCost" name="Cost" style="width: 40px; text-align: right;" value="<%=cost %>" />
                </td>
            </tr>
            <tr>
                <td>
                    满包邮：
                </td>
                <td>
                    <input type="text" id="inputGreaterThan" name="GreaterThan" style="width: 40px; text-align: right;" value="<%=cost %>" />
                </td>
            </tr>

        </table>
        
        <br/>
        省份：
        <input type="checkbox" id="selectAll" onclick="CheckAll();" /><label for="selectAll">全选</label>
        <input type="button" onclick="CheckReverse();" value="反选" />
        <input type="button" onclick="CheckNear();" value="偏远除外" />
        <br/>
    
        <asp:Repeater runat="server" ID="provinceRepeater" >
            <ItemTemplate>
                <input type="checkbox" name="selectedProvince" id="cb<%#Eval("Name") %>" value="<%#Eval("Name") %>" /><label for="cb<%#Eval("Name") %>"><%#Eval("Name") %></label>
            </ItemTemplate>
        </asp:Repeater>
               
        <br/>
        <input type="submit" value="保存" />
        
    </form>
    
</asp:Content>
